package com.wc.算法提高课.D第四章_高级数据结构.并查集.格子游戏;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/15 17:20
 * @description https://www.acwing.com/problem/content/1252/
 */
public class Main {
    /**
     * 思路：将每一个点，看成图中的一个点，下一个点看成图中的另一个点，我们可以用并查集连接，
     * 如果说两个点已经在同一个集合当中，那就说明已经成了闭环了，如果没有，将这两个点加入到集合当中
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 210, M = N * N;
    static int[] p = new int[M];
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i < n * n; i++) p[i] = i;
        int res = 0;
        for (int i = 1; i <= m; i++) {
            int x = sc.nextInt(), y = sc.nextInt();
            x--;
            y--;
            int a = get(x, y), b;
            String op = sc.next();
            if (op.equals("D")) b = get(x + 1, y);
            else b = get(x, y + 1);
            a = find(a);
            b = find(b);
            if (a == b) {
                res = i;
                break;
            }
            p[a] = b;
        }
        if (res > 0) out.println(res);
        else out.println("draw");
        out.flush();
    }

    static int get(int x, int y) {
        return x * n + y;
    }

    static int find(int x) {
        if (p[x] != x) p[x] = find(p[x]);
        return p[x];
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
